package cn.org.itool.ws.framework.comment;

import cn.org.itool.ws.framework.listener.BroadcastCloseMessageListener;
import cn.org.itool.ws.framework.listener.BroadcastMessageListener;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;


@Lazy(false)
@Component
public class BroadcastRegisterComment {

    public static final String BROADCAST_TOPIC ="sys.ws.broadcast.message";

    public static final String BROADCAST_CLOSE_TOPIC ="sys.ws.broadcast.close.message.";

    @Resource
    private RedisMessageListenerContainer redisMessageListenerContainer;


    @PostConstruct
    private void init() {
        System.out.println("init BroadcastRegisterComment");

        redisMessageListenerContainer.addMessageListener(new MessageListenerAdapter(new BroadcastMessageListener()), new ChannelTopic(BROADCAST_TOPIC));
        redisMessageListenerContainer.addMessageListener(new MessageListenerAdapter(new BroadcastCloseMessageListener()), new ChannelTopic(BROADCAST_CLOSE_TOPIC));
    }

}
